﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Xml;

public partial class ws_SP_PermDocs_FilesInfo_ByDocSetID_DeepZoom : WSPageBase
{

    #region Page Events

    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        // Enabled trace in code
        this.Context.Trace.IsEnabled = false;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        XmlDocument xReturn = getXML();
        Response.ContentType = "text/xml";
        Response.Write(xReturn.OuterXml);
    }

    #endregion

    #region Data

    public XmlDocument getXML()
    {
        int i = -1;
        string urlTmp = "";
        XmlDocument xReturn = new XmlDocument();

        DataTable tbl = new DataTable("tbl");
        Ko2.Portal.SP_List.SPList_PermDocs o = new Ko2.Portal.SP_List.SPList_PermDocs();
        Exception err = null;
        if (intID != -1)
        {
            err = o.GetFilesListByItemId(ref tbl, intID);
            if (err != null)
                MakeXML(ref xReturn, ref tbl, ref err);
            else
            {

                /*
                <?xml version='1.0'?> 
                <SceneGraph version='1'>
                    <AspectRatio>1.33333333333334</AspectRatio>
                    <SceneNode>
                        <FileName>C:\Code\SLBook\Chapter11\DZCSample\source images\dzcsample\DSCN2961.JPG</FileName>
                        <x>0</x>
                        <y>0</y>
                        <Width>1</Width>
                        <Height>1</Height>
                        <ZOrder>1</ZOrder>
                    </SceneNode>
                    <SceneNode>
                        <FileName>C:\Code\SLBook\Chapter11\DZCSample\source images\dzcsample\DSCN2959.JPG</FileName>
                        <x>0.451782754964542</x>
                        <y>0.313488814592021</y>
                        <Width>0.00099432659277551</Width>
                        <Height>0.00099432659277551</Height>
                        <ZOrder>2</ZOrder>
                    </SceneNode>
                </SceneGraph>
                */

                Response.Write(
@"
<SceneGraph version='1'>
    <AspectRatio>1.33333333333334</AspectRatio>
");
                foreach (DataRow r in tbl.Rows)
                {

                    i++;
                    urlTmp = @"http://sp.korablik.local" + r["ServerRelativeUrl"] ?? "";
                    Response.Write(
@"
    <SceneNode>
        <FileName>" + urlTmp + @"</FileName>
        <x>0." + i.ToString() + @"0000000000000001</x>
        <y>0." + i.ToString() + @"0000000000000001</y>
        <Width>1</Width>
        <Height>1</Height>
        <ZOrder>" + i.ToString() + @"</ZOrder>
    </SceneNode>
");

                }

                Response.Write(
@"</SceneGraph>
");
            }
        }
        return xReturn;
    }

    #endregion

}
